//getElementById
function _id(id) {
	return document.getElementById(id);
}

//output information
function Output(msg){
	var m = _id("messages");
	m.innerHTML = msg + m.innerHTML;
}

//call init file
if (window.File && window.FileList && window.FileReader){
	Init();
}

//initialise
function Init(){
	
	var fileselect = _id("file"),
		filedrag = _id("filedrag"),
		submitbutton = _id("submitbutton");

	// file select
	fileselect.addEventListener("change", FileSelectHandler, false);

	// is XHR2 available?
	var xhr = new XMLHttpRequest();
	if (xhr.upload) {
	
		// file drop
		filedrag.addEventListener("dragover", FileDragHover, false);
		filedrag.addEventListener("dragleave", FileDragHover, false);
		filedrag.addEventListener("drop", FileSelectHandler, false);
		filedrag.style.display = "block";
		
		// remove submit button
		submitbutton.style.display = "none";
	}

}

// file drag hover
function FileDragHover(e) {
	e.stopPropagation();
	e.preventDefault();
	e.target.className = (e.type == "dragover" ? "hover" : "");
}